<template>
	<view class='page_cont'>
		<view class='top'>
			<view class='search_wrap'>
				<view class='search_box'>
					<image class='icon' src="/static/icon26.png"></image>
					<input type="text" class='input' placeholder="搜索企业名称" :focus="focus" confirm-type="search" @input="input_search" @confirm="confirm_search">
				</view>
				<view class='search_btn' @click="confirm_search">搜索</view>
			</view>
		</view>
		<view class='ti'>根据您输入的关键词设置后，含该关键词的单位都会被屏蔽，无 法搜索到你简历信息</view>
		<scroll-view class='list' scroll-y="true" scroll-with-animation="true" @scrolltolower='scrollBottom'>
			<mechItem :mechs="mechs" :status="3" @hideCompany="hide_company" v-if='mechs.length>0'></mechItem>
			<view class='no_cont' v-if="show_nav">
				<view class="no_box">
				    <view class='title'>暂无机构信息</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import config from "../../api/config.js"
	import myResume from "../../api/myResume.js"
	import util from "../../utils/util.js"
	import MechItem from "../../components/mechItem.vue"
	export default{
		data(){
			return{
				word: '',
				mechs: [],
				len: '',
				ids: [],
				add: false,
				currentPage: 1,
				pageSize: 10,
				latitude: 22.820794,
				longitude: 113.284565,
				hasMoreData: true,
				show_nav: false,
				focus: false
			}
		},
		onLoad(options) {
			// console.log(options)
			this.len=options.len;
			this.ids=options.ids.split(",");
			this.latitude=uni.getStorageSync("user_address").lat;
			this.longitude=uni.getStorageSync("user_address").lng;
		},
		methods:{
			// 输入框
			input_search(e){
				this.word=e.detail.value;
				this.focus=true
			},
			// 搜索
			confirm_search(e){
				var word=e.detail.value?e.detail.value:this.word;
				if(!word||util.testWord(word)){
				    util.page_show_toast('请输入关键字搜索',1500);
				}else{
				    word=util.removeAllSpace(word);
					this.word=word;
					this.currentPage=1;
					this.mechs=[];
					this.show_nav=false;
					this.focus=false;
					this.search_org();
				}
			},
			// 触底
			scrollBottom(){
				if(this.hasMoreData){
					this.search_org()
				}else{
					util.page_show_toast('没有更多了',1500)
				}
			},
			// 搜索列表
			search_org(word){
				uni.showLoading({})
				var params={
					"keyword": this.word,
					"lat": this.latitude,
					"lng": this.longitude,
					"currentPage": this.currentPage,
					"pageSize": this.pageSize
				}
				myResume.search_org(params).then(res=>{
					uni.hideLoading();
					var list=res.data.data.records;
					list.forEach((item)=>{
						item.space=item.distance>1000?(item.distance/1000).toFixed(2):item.distance;
					})
					var mechs=util.extend(this.mechs, list)
					if (list.length < this.pageSize) {
						this.mechs=mechs;
						this.hasMoreData=false;
					} else {
						this.mechs=mechs;
						this.hasMoreData=true;
						this.currentPage=this.currentPage+1;
					}
					if(list.length==0&&mechs.length==0){
						this.show_nav=true;
					}
				})
			},
			// 屏蔽
			hide_company(index){
				if(this.add){
					console.log('---- 请勿重复点击 ----')
					return false;
				}
				if(this.len>=3){
					util.page_show_toast("最多屏蔽三家企业",1500);
					return false;
				}
				for(var i=0;i<this.ids.length;i++){
					if(this.mechs[index].id==this.ids[i]){
						util.page_show_toast("您已屏蔽该企业",1500);
						return false;
					}
				}
				var params={
					"businessName": this.mechs[index].name,
					"businessId": this.mechs[index].id,
					"businessLogo": this.mechs[index].logoImg
				}
				config.add_corpor(params).then(res=>{
					util.page_show_toast("屏蔽成功",1500);
					this.add=true;
					var pages = getCurrentPages();
					var prevPage = pages[pages.length - 2];
					prevPage.$vm.add=true;
					setTimeout(()=>{
						uni.navigateBack({
							delta: 1
						})
					},1500)
				})
			}
		},
		components:{
			mechItem: MechItem
		}
	}
</script>

<style lang="scss">
	.page_cont{
		padding: 16rpx 32rpx;
		.top{
			padding-bottom: 32rpx;
			.search_wrap{
				display: flex;
				flex-direction: row;
				background: #F6F7F9;
				border-radius: 12rpx;
				.search_box{
					flex: 1;
					padding: 12rpx;
					display: flex;
					flex-direction: row;
					align-items: center;
					.icon{
						width: 32rpx;
						height: 32rpx;
						margin-right: 8rpx;
					}
					.input{
						flex: 1;
						height: 40rpx;
						font-size: 28rpx;
						font-weight: 500;
						line-height: 40rpx;
						color: rgba(146,155,167,0.81);
					}
				}
				.search_btn{
					width: 120rpx;
					height: 64rpx;
					text-align: center;
					line-height: 64rpx;
					background: #5B90FF;
					border-radius: 12rpx;
					font-size: 28rpx;
					font-weight: 500;
					color: rgba(255,255,255,0.81)
				}
			}
		}
		.ti{
			text-align: left;
			font-size: 24rpx;
			font-weight: 400;
			line-height: 36rpx;
			color: rgba(121,133,148,0.5);
			margin-bottom: 40rpx;
		}
		.list{
			height: 78vh;
			background: #f7f6f9;
		}
		.no_cont{
			width: 520rpx;
			margin: 0 auto;
			padding-top: 160rpx;
			.no_box{
				width: 100%;
				height: 520rpx;
				box-sizing: border-box;
				padding-top: 360rpx;
				background: url("https://ossdev0.jiabala.com/4B57SRMriNNbG") no-repeat 0 0/100% 100%;
				.title{
					text-align: center;
					height: 50rpx;
					font-size: 32rpx;
					font-weight:400;
					line-height: 50rpx;
					color: #3F4A58;
				}
				.text{
					margin-top: 8rpx;
					text-align: center;
					height: 40rpx;
					font-size: 28rpx;
					font-weight:400;
					line-height: 40rpx;
					color: #798594;
				}
			}
		}
	}
</style>
